package animal2;


public class Dog {
    //成员属性:昵称 年龄 体重 品种

    //修改属性的可见性
    private  String name;//String类型默认值null
    private double age;//double类型默认值0.0
    private double weight;
    private String species;
    //创建get/set方法,在get/set方法中添加对属性的限定
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return this.name;
    }

    public double getAge() {
        return age;
    }

    public void setAge(double age) {
        if (age<0){
            System.out.println("输入年龄信息有误,年龄必须大于0");
        }else {
            this.age = age;
        }
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public String getSpecies() {
        return species;
    }

    public void setSpecies(String species) {
        this.species = species;
    }

    //成员方法:跑动 吃东西
    public void run(String name){
        System.out.println(name+"狗狗快跑");
    }
    public void eat(String name){
        System.out.println(name+"狗狗吃骨头");
    }
    //构造方法
    public Dog(){
        System.out.println("我是宠物狗!");
    }
    public Dog(String name,double age,double weight,String species){
        //this代表当前对象
        this.setName(name);
        this.setAge(age);
        this.setWeight(weight);
        this.setSpecies(species);
    }
}
